/*============================================================================*/
/*  Copyright (C) 2009-2015, iSOFT INFRASTRUCTURE SOFTWARE CO.,LTD.
 *
 *  All rights reserved. This software is iSOFT property. Duplication
 *  or disclosure without iSOFT written authorization is prohibited.
 *
 *  @file       <PduR.c>
 *  @brief      <PDUR>
 *
 *  <Compiler: 	    MCU:NONE>
 *
 *  @author     <Huanyu.Zhao>
 *  @date       <2015-04-01>
 */
/*============================================================================*/

/*=======[R E V I S I O N   H I S T O R Y]====================================*/
/*  <VERSION>    <DATE>    <AUTHOR>    <REVISION LOG>
 *  V1.0.0     20150401  Huanyu.Zhao Initial version
 *
 */
/*============================================================================*/

/*=======[V E R S I O N  I N F O R M A T I O N]===============================*/
#define PDUR_C_AR_MAJOR_VERSION  2U
#define PDUR_C_AR_MINOR_VERSION  3U
#define PDUR_C_AR_PATCH_VERSION  0U
#define PDUR_C_SW_MAJOR_VERSION  1U
#define PDUR_C_SW_MINOR_VERSION  0U
#define PDUR_C_SW_PATCH_VERSION  0U

/*=======[I N C L U D E S]====================================================*/
#include "PduR.h"

#if(STD_ON == PDUR_DEV_ERROR_DETECT)
#include "Det.h"
#endif

#if(STD_ON == PDUR_DEM_ERROR_DETECT)
#include "Dem.h"
#endif

#include "PduR_Cbk.h"
#include "SchM_PduR.h"


#if(STD_ON == PDUR_COM_SUPPORT)
#include "PduR_Com.h"
#endif

#if(STD_ON == PDUR_CANIF_SUPPORT)
#include "PduR_CanIf.h"
#endif
#if(STD_ON == PDUR_LINIF_SUPPORT)
#include "PduR_LinIf.h"
#endif


#if(STD_ON == PDUR_IPDUM_SUPPORT)
#include "PduR_Ipdum.h"
#endif

/*=======[V E R S I O N  C H E C K]===========================================*/
#if (PDUR_C_AR_MAJOR_VERSION != PDUR_H_AR_MAJOR_VERSION)
  #error "PduR.c : Mismatch in Specification Major Version"
#endif
#if (PDUR_C_AR_MINOR_VERSION != PDUR_H_AR_MINOR_VERSION)
  #error "PduR.c : Mismatch in Specification Major Version"
#endif
#if (PDUR_C_AR_PATCH_VERSION != PDUR_H_AR_PATCH_VERSION)
  #error "PduR.c : Mismatch in Specification Major Version"
#endif
#if (PDUR_C_SW_MAJOR_VERSION != PDUR_H_SW_MAJOR_VERSION)
  #error "PduR.c : Mismatch in Specification Major Version"
#endif
#if (PDUR_C_SW_MINOR_VERSION != PDUR_H_SW_MINOR_VERSION)
  #error "PduR.c : Mismatch in Specification Major Version"
#endif

#if STD_ON == COM_DEV_ERROR_DETECT
#if( 2u != DET_H_AR_MAJOR_VERSION)
    #error "PduR.c : Mismatch in Specification Major Version"
#endif

#if( 2u != DET_H_AR_MINOR_VERSION)
    #error "PduR.c : Mismatch in Specification Minor Version"
#endif
#endif

#if( 2u != PDUR_CBK_H_AR_MAJOR_VERSION)
    #error "PduR.c : Mismatch in Specification Major Version"
#endif

#if( 3u != PDUR_CBK_H_AR_MINOR_VERSION)
    #error "COM.c : Mismatch in Specification Minor Version"
#endif


/*=======[M A C R O S]========================================================*/
#if(STD_OFF == PDUR_ZERO_COST_OPERATION)

/*=======[T Y P E   D E F I N I T I O N S]====================================*/
#if(STD_ON == PDUR_GATEWAY_OPERATION)
typedef struct
{
    /* Queue front */
    uint8 First;
    /* Queue rear */
    uint8 Last;
    /* Queue count */
    uint8 Count;    
    boolean TxConfP;
}PduR_TxBufferTableRuntimeType;
#endif /* #if(STD_ON == PDUR_GATEWAY_OPERATION) */
/*=======[M A C R O   F U N C T I O N]========================================*/
#if(PDUR_VARIANT_PB == PDUR_VARIANT_CFG)

#define PDUR_START_SEC_CONST_16BIT
#include "PduR_MemMap.h"
extern CONST(uint16, PDUR_CONST) PduRTxBufferSize;
#define PDUR_STOP_SEC_CONST_16BIT
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CONST_16BIT
#include "PduR_MemMap.h"
extern CONST(uint16, PDUR_CONST) PduRGWDestTxPduSize;
#define PDUR_STOP_SEC_CONST_16BIT
#include "PduR_MemMap.h"

#define PDUR_GETCONFIGURATIONID         (PduR_ConfigStd->PduRConfigId)
#define PDUR_GWDESTTXPDU_NUM             (PduRGWDestTxPduSize)  
#define PDUR_TXBUFFER_NUM                    (PduRTxBufferSize)  
#define PDUR_COMDESTTXPDU(PduId)        (PduR_ConfigStd->PduRComDestTxPduRef[PduId]) 
#define PDUR_IFCONFPDU(PduId)                (PduR_ConfigStd->PduRIfConfPduRef[PduId]) 
#define PDUR_GWDESTTXPDU(PduId)          (PduR_ConfigStd->PduRGWDestTxPduRef[PduId]) 
#define PDUR_IFDESTRXPDU(PduId)             (PduR_ConfigStd->PduRIfDestRxPduRef[PduId]) 
#define PDUR_IFSRCRXPDU(PduId)               (PduR_ConfigStd->PduRIfSrcRxPduRef[PduId])
#define PDUR_IPDUMRXPDU(PduId)               (PduR_ConfigStd->PduRIpduMRxPduRef[PduId])

#else /* PDUR_VARIANT_PC */
#define PDUR_GETCONFIGURATIONID         (PDUR_GETCONFIGURATION_ID)
#define PDUR_GWDESTTXPDU_NUM             (PDUR_MAX_GWDESTTXPDU_NUMBER)
#define PDUR_TXBUFFER_NUM                    (PDUR_MEMORY_SIZE)  
#define PDUR_COMDESTTXPDU(PduId)        (PduRComDestTxPdu[PduId]) 
#define PDUR_IFCONFPDU(PduId)                (PduRIfConfPdu[PduId]) 
#define PDUR_GWDESTTXPDU(PduId)          (PduRGWDestTxPdu[PduId]) 
#define PDUR_IFDESTRXPDU(PduId)             (PduRIfDestRxPdu[PduId]) 
#define PDUR_IFSRCRXPDU(PduId)               (PduRIfSrcRxPdu[PduId])
#define PDUR_IPDUMRXPDU(PduId)              (PduRIpduMRxPdu[PduId])

#endif /* #if(PDUR_VARIANT_PB == PDUR_VARIANT_CFG) */
/*=======[I N T E R N A L   R A M  D A T A]==========================================*/
#define PDUR_START_SEC_CONST_UNSPECIFIED
#include "PduR_MemMap.h"
STATIC P2CONST(PduR_PBConfigType, PDUR_CONST, PDUR_CONST_PBCFG) PduR_ConfigStd;
#define PDUR_STOP_SEC_CONST_UNSPECIFIED
#include "PduR_MemMap.h"

#define PDUR_START_SEC_VAR_POWER_ON_INIT_UNSPECIFIED
#include "PduR_MemMap.h"
/* PduR init status, at first define it as PDUR_UNINIT */
STATIC VAR(PduR_StateType, PDUR_VAR_POWER_ON_INIT) PduR_Status = PDUR_UNINIT;
#define PDUR_STOP_SEC_VAR_POWER_ON_INIT_UNSPECIFIED
#include "PduR_MemMap.h"

#if (STD_ON == PDUR_GATEWAY_OPERATION)
#define PDUR_START_SEC_VAR_UNSPECIFIED
#include "PduR_MemMap.h"
STATIC VAR(PduR_TxBufferTableRuntimeType, PDUR_VAR) TxBufferTableRuntimer[PDUR_MAX_GWDESTTXPDU_NUMBER];
#define PDUR_STOP_SEC_VAR_UNSPECIFIED
#include "PduR_MemMap.h"


/* define Tx Buffers */
#define PDUR_START_SEC_VAR_UNSPECIFIED
#include "PduR_MemMap.h"
VAR(uint8, PDUR_CONST) PduRGWTxBuffer[PDUR_MEMORY_SIZE];
#define PDUR_STOP_SEC_VAR_UNSPECIFIED
#include "PduR_MemMap.h"

#endif /* #if (STD_ON == PDUR_FIFO_TX_BUFFER_SUPPORT) */


/*=======[I N T E R N A L   F U N C T I O N   D E C L A R A T I O N S]========*/
#if(STD_ON == PDUR_GATEWAY_OPERATION)
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_GWRxIndication(PduIdType RxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(boolean, PDUR_CODE)
PduR_IsFullBuffer(PduIdType PduId);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_EnQueueBuffer(PduIdType PduId);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_DeQueueBuffer(PduIdType PduId);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"


#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_FIFOFlush(PduIdType PduId);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(Std_ReturnType, PDUR_CODE)
PduR_TransmitBuffer(PduIdType RxPduId,  P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_GWTxConfirmation(PduIdType TxPduId);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#endif /* #if(STD_ON == PDUR_GATEWAY_OPERATION) */

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
/* Memcpy and Memset for PduR Mode used */
STATIC FUNC(void, PDUR_CODE)
PduR_Memcpy
(
    P2VAR(uint8, AUTOMATIC, AUTOMATIC) dest,
    P2CONST(uint8, AUTOMATIC, AUTOMATIC) source,
    uint16 length
);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_Memset
(
    P2VAR(uint8, AUTOMATIC, AUTOMATIC) dest,
    const uint8 source,
    uint16 length
);
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/*=======[A P I   I M P L E M E N T A T I O N S]====================*/
/******************************************************************************/
/*
 * Brief               Initializes the PDU Router
 *
 * ServiceId           0x00
 * Sync/Async          Synchronous
 * Reentrancy          Non Reentrant
 * Param-Name[in]      ConfigPtr: Pointer to Post build configuration data.
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(void, PDUR_CODE)
PduR_Init(P2CONST(PduR_PBConfigType, AUTOMATIC, PDUR_CONST_PBCFG) ConfigPtr)
{
	uint8	i = 0;

	#if(STD_ON == PDUR_DEV_ERROR_DETECT)
	boolean detNoErr = TRUE;

	/* @PDUR337 */
	if(PDUR_UNINIT != PduR_Status)
	{
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_INIT_ID, PDUR_E_INVALID_REQUEST);
		detNoErr = FALSE;
		PduR_Status = PDUR_REDUCED;
	}
       #if(PDUR_VARIANT_PB == PDUR_VARIANT_CFG) 
        if ((TRUE == detNoErr) && (NULL_PTR == ConfigPtr))
        {
            /* @PDUR222 */
            Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_INIT_ID, PDUR_E_CONFIG_PTR_INVALID);
            detNoErr = FALSE;
            PduR_Status = PDUR_REDUCED;
        }
        #endif /* #if(PDUR_VARIANT_PB == PDUR_VARIANT_CFG)  */
	if(TRUE == detNoErr)
	#endif
	{
            #if(PDUR_VARIANT_PB == PDUR_VARIANT_CFG)  
            PduR_ConfigStd = ConfigPtr;
            #endif /* #if(PDUR_VARIANT_PB == PDUR_VARIANT_CFG) */  

		/* @PDUR308 @PDU311 @PDUR313 */
		#if(STD_ON == PDUR_GATEWAY_OPERATION)
		for(i = 0; i < PDUR_GWDESTTXPDU_NUM; i++)
		{
		      /* Init queue */
        		TxBufferTableRuntimer[i].First = PDUR_GWDESTTXPDU(i).Start;
        		TxBufferTableRuntimer[i].Last = PDUR_GWDESTTXPDU(i).Start;
                    TxBufferTableRuntimer[i].Count = 0;
        		TxBufferTableRuntimer[i].TxConfP = FALSE;
		}
		#endif
		PduR_Status = PDUR_ONLINE;
	}

	return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief               Returns the unique identifier of the Post build time
 * 						configuration of the PDU Router.
 *
 * ServiceId           0x18
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      None
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              uint32 Identifier of the post build time configuration.
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(uint32, PDUR_CODE)
PduR_GetConfigurationId(void)
{
	return (PDUR_GETCONFIGURATIONID);
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief				This service primitive is used to cancel the transfer
 * 						of pending I-PDUs. This function has to be called with
 * 						the PDU-Id and the reason for cancellation.
 *
 * ServiceId           0x1c
 * Sync/Async          Asynchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      PduCancelReason:The reason for cancellation
 * 					   PduId:This parameter contains the unique identifier of
 * 					   the I-PDU which transfer has to be cancelled.
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return			   std_ReturnType :E_OK Cancellation request of the transfer
 * 						of the specified I-PDU is accepted.
 * 						E_NOT_OK:Cancellation request of the transfer of the
 * 						specified I-PDU is rejected.
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(Std_ReturnType, PDUR_CODE)
PduR_CancelTransmitRequest(PduR_CancelReasonType PduCancelReason, PduIdType PduId)
{
	return E_NOT_OK;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief               This Service primitive is used to request the change of
 * 						the value of the PDUR_STMIN parameter.the new value is
 * 						given by PduParameterValue.
 *
 * ServiceId           0x1d
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      None
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              uint32 Identifier of the post build time configuration.
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(uint32, PDUR_CODE)
PduR_ChangeParameterRequest(PduR_ParameterValueType PduParameterValue, PduIdType PduId)
{
	return 0;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief               Requests a tranmission for the Com module
 *
 * ServiceId           0x15
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      CanTxPduId:ID of COM I-PDU that has been transmitted.
 * 					   PduInfoPtr: Contains the lenght of the received I-PDU
 * 					   and a pointer to a buffer containing the I-SDU.
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
/* @PDUR407 */
#if(STD_ON == PDUR_COM_SUPPORT)
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(Std_ReturnType, PDUR_CODE)
PduR_ComTransmit(PduIdType ComTxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
	Std_ReturnType result = E_NOT_OK;

	#if(STD_ON == PDUR_DEV_ERROR_DETECT)
	boolean detNoErr = TRUE;
	/* @PDUR337 */
	if(PDUR_ONLINE != PduR_Status)
	{
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_COMTRANSMIT_ID, PDUR_E_INVALID_REQUEST);
		detNoErr = FALSE;
	}
	if ((TRUE == detNoErr) && ((NULL_PTR == PduInfoPtr) || (NULL_PTR == PduInfoPtr->SduDataPtr)))
	{
		/* @PDUR222 */
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_COMTRANSMIT_ID, PDUR_E_DATA_PTR_INVALID);
		detNoErr = FALSE;
	}
	if ((TRUE == detNoErr) && (ComTxPduId >= PDUR_MAX_COMDESTTXPDU_NUMBER))
	{
		/* @PDUR222 */
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_COMTRANSMIT_ID, PDUR_E_PDU_ID_INVALID);
		detNoErr = FALSE;
	}
	if(TRUE == detNoErr)
	#endif
	{
		result = PduRLoIf_Transmit[(PDUR_COMDESTTXPDU(ComTxPduId).BusType)](PDUR_COMDESTTXPDU(ComTxPduId).DestId, PduInfoPtr);
	}

	return result;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"
#endif /* endif #if(STD_ON == PDUR_COM_SUPPORT) */

/******************************************************************************/
/*
 * Brief               Rx indicator for the CAN Interface
 *
 * ServiceId           0x01
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      CanRxPduId:ID of CAN L-PDU that has been received.
 * 					   PduInfoPtr: Contains the lenght of the received I-PDU
 * 					   and a pointer to a buffer containing the I-PDU.
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
/* @PDUR345 @PDUR349 */
#if(STD_ON == PDUR_CANIF_SUPPORT)
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(void, PDUR_CODE)
PduR_CanIfRxIndication(PduIdType CanRxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
	uint16 PduIndex = 0;

	#if(STD_ON == PDUR_DEV_ERROR_DETECT)
	boolean detNoErr = TRUE;
	/* @PDUR337 */
	if(PDUR_ONLINE != PduR_Status)
	{
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_CANIFRXINDICATION_ID, PDUR_E_INVALID_REQUEST);
		detNoErr = FALSE;
	}
	if ((TRUE == detNoErr) && ((NULL_PTR == PduInfoPtr) || (NULL_PTR == PduInfoPtr->SduDataPtr)))
	{
		/* @PDUR222 */
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_CANIFRXINDICATION_ID, PDUR_E_DATA_PTR_INVALID);
		detNoErr = FALSE;
	}
	if ((TRUE == detNoErr) && (CanRxPduId >= PDUR_MAX_IFSRCRXPDU_NUMBER))
	{
		/* @PDUR222 */
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_CANIFRXINDICATION_ID, PDUR_E_PDU_ID_INVALID);
		detNoErr = FALSE;		
	}

	if(TRUE == detNoErr)
	#endif
	{
		for(PduIndex=PDUR_IFSRCRXPDU(CanRxPduId).StartId; PduIndex <= PDUR_IFSRCRXPDU(CanRxPduId).StopId; PduIndex++)
		{
			switch (PDUR_IFDESTRXPDU(PduIndex).UpType)
			{
				#if(STD_ON == PDUR_COM_SUPPORT)
				case PDUR_COM:
					Com_RxIndication(PDUR_IFDESTRXPDU(PduIndex).DestId, PduInfoPtr);
					break;
				#endif
				#if(STD_ON == PDUR_IPDUM_SUPPORT)
				case PDUR_IPDUMU:
					Ipdum_RxIndication(PDUR_IFDESTRXPDU(PduIndex).DestId, PduInfoPtr);
					break;
				#endif
				#if(STD_ON == PDUR_GATEWAY_OPERATION)
				case PDUR_GATEWAY:   
                                 PduR_GWRxIndication(PDUR_IFDESTRXPDU(PduIndex).DestId, PduInfoPtr);
					break;
				#endif
				default:
					break;
			}

		}
	}
	return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#if(STD_ON == PDUR_GATEWAY_OPERATION)
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_GWRxIndication(PduIdType RxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
    Std_ReturnType result = E_NOT_OK;
    Std_ReturnType ret = E_NOT_OK;

    /* transmit request */      
    do
    {
        /* If TxConfp is not set */
        if(FALSE == TxBufferTableRuntimer[RxPduId].TxConfP)
        {
            if(PDUR_LIN == PDUR_GWDESTTXPDU(RxPduId).BusType)
            {
                /* add I-pdu to Tx buffer */
                ret = PduR_TransmitBuffer(RxPduId, PduInfoPtr);                        
            }
            /* Call LoIf_Transmit */
    	    result = PduRLoIf_Transmit[PDUR_GWDESTTXPDU(RxPduId).BusType](PDUR_GWDESTTXPDU(RxPduId).DestId, PduInfoPtr);
            if(E_OK == result)
            {
                TxBufferTableRuntimer[RxPduId].TxConfP = TRUE;
                ret = E_OK;
            }
           else
           {
                ret = E_NOT_OK;
               #if(STD_ON == PDUR_DEM_ERROR_DETECT)
               Dem_ReportErrorStatus(PDUR_E_PDU_INSTANCE_LOST, DEM_EVENT_STATUS_FAILED);
               #endif /* #if(STD_ON == PDUR_DEM_ERROR_DETECT) */
                if(PDUR_LIN == PDUR_GWDESTTXPDU(RxPduId).BusType)
                {
                    /* if Transmit return without success then clean the FIFO */   
                    PduR_DeQueueBuffer(RxPduId);
                }
           }    
        }
        /* TxConfP is set */
        else
        {
            ret = PduR_TransmitBuffer(RxPduId, PduInfoPtr);
        }
    }while(E_OK != ret);
    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(boolean, PDUR_CODE)
PduR_IsFullBuffer(PduIdType PduId)
{
    boolean rev = FALSE;

    /* FIFO is full  */
    if(TxBufferTableRuntimer[PduId].Count == PDUR_GWDESTTXPDU(PduId).Depth)
    {
        rev = TRUE;
    }
    return rev;    
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_EnQueueBuffer(PduIdType PduId)
{
    TxBufferTableRuntimer[PduId].Last = TxBufferTableRuntimer[PduId].Last + PDUR_GWDESTTXPDU(PduId).Length;
    TxBufferTableRuntimer[PduId].Count++;
    if(TxBufferTableRuntimer[PduId].Last == (PDUR_GWDESTTXPDU(PduId).Length * PDUR_GWDESTTXPDU(PduId).Depth))
    {
        TxBufferTableRuntimer[PduId].Last = PDUR_GWDESTTXPDU(PduId).Start;
    }
    return;    
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_DeQueueBuffer(PduIdType PduId)
{
    if(TxBufferTableRuntimer[PduId].Count > 0u)
   {
        TxBufferTableRuntimer[PduId].First= TxBufferTableRuntimer[PduId].First + PDUR_GWDESTTXPDU(PduId).Length;
        TxBufferTableRuntimer[PduId].Count--;
        if(TxBufferTableRuntimer[PduId].First == (PDUR_GWDESTTXPDU(PduId).Length * PDUR_GWDESTTXPDU(PduId).Depth))
        {
            TxBufferTableRuntimer[PduId].First = PDUR_GWDESTTXPDU(PduId).Start;
        }
   }
   return;

}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"


#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_FIFOFlush(PduIdType PduId)
{
    /* @PDUR305 Flush-on-overrun */
    TxBufferTableRuntimer[PduId].First = PDUR_GWDESTTXPDU(PduId).Start;
    TxBufferTableRuntimer[PduId].Last= PDUR_GWDESTTXPDU(PduId).Start;
    TxBufferTableRuntimer[PduId].Count = 0u;
    TxBufferTableRuntimer[PduId].TxConfP= FALSE;
    return;    
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(Std_ReturnType, PDUR_CODE)
PduR_TransmitBuffer(PduIdType RxPduId,  P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
    Std_ReturnType ret = E_NOT_OK;
	
    /* FIFO is full */
    if(TRUE == PduR_IsFullBuffer(RxPduId))
    {
        /* Flush the FIFO */
        PduR_FIFOFlush(RxPduId);
        #if(STD_ON == PDUR_DEM_ERROR_DETECT)
        Dem_ReportErrorStatus(PDUR_E_PDU_INSTANCE_LOST, DEM_EVENT_STATUS_FAILED);
        #endif
        ret = E_NOT_OK;
    }
    else
    {
        /* FIFO is not full,  add the new I-PDU to the FIFO */
        if((PduInfoPtr->SduLength) < PDUR_GWDESTTXPDU(RxPduId).Length)
        {
            PduR_Memcpy(&PduRGWTxBuffer[TxBufferTableRuntimer[RxPduId].Last],
        			        PduInfoPtr->SduDataPtr,
        			        PduInfoPtr->SduLength);  
            /* set remain Buffer default value */
            PduR_Memset(&PduRGWTxBuffer[TxBufferTableRuntimer[RxPduId].Last+PduInfoPtr->SduLength], 
        			PDUR_GWDESTTXPDU(RxPduId).DefaultValue, 
        			(PDUR_GWDESTTXPDU(RxPduId).Length - PduInfoPtr->SduLength));     
        }
        else
        {
            PduR_Memcpy(&PduRGWTxBuffer[TxBufferTableRuntimer[RxPduId].Last],
        			        PduInfoPtr->SduDataPtr,
        			        PDUR_GWDESTTXPDU(RxPduId).Length); 
        }
        /* FIFO increment Queue */
        PduR_EnQueueBuffer(RxPduId);
        ret = E_OK;
    }
        
    return ret;
}

#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#endif /* #if(STD_ON == PDUR_GATEWAY_OPERATION) */

/******************************************************************************/
/*
 * Brief               Tx confirmation for the CAN Interface
 *
 * ServiceId           0x02
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      CanTxPduId:ID of CAN L-PDU that has been Transmitted.
 *
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(void, PDUR_CODE)
PduR_CanIfTxConfirmation(PduIdType CanTxPduId)
{
    #if(STD_ON == PDUR_DEV_ERROR_DETECT)
    boolean detNoErr = TRUE;
    /* @PDUR337 */
    if(PDUR_ONLINE != PduR_Status)
    {
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_CANIFTXCONFIRMATION_ID, PDUR_E_INVALID_REQUEST);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && (CanTxPduId >= PDUR_MAX_IFCONFPDU_NUMBER))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_CANIFTXCONFIRMATION_ID, PDUR_E_PDU_ID_INVALID);
    	detNoErr = FALSE;		
    }
    if(TRUE == detNoErr)
    #endif
    {
        switch (PDUR_IFCONFPDU(CanTxPduId).UpType)
        {
            #if(STD_ON == PDUR_COM_SUPPORT)
             case PDUR_COM:
        	    Com_TxConfirmation(PDUR_IFCONFPDU(CanTxPduId).ConfId);
        	    break;
             #endif
            #if(STD_ON == PDUR_IPDUM_SUPPORT)
            case PDUR_IPDUMU:
        	    Ipdum_TxConfirmation(PDUR_IFCONFPDU(CanTxPduId).ConfId);
        	    break;
            #endif
            #if(STD_ON == PDUR_GATEWAY_OPERATION)
            case PDUR_GATEWAY:
                PduR_GWTxConfirmation(PDUR_IFCONFPDU(CanTxPduId).ConfId);
        	    break;
            #endif
            default:
        	    break;
        }           
    }   
    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"


#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_GWTxConfirmation(PduIdType TxPduId)
{
    Std_ReturnType result = E_NOT_OK;
    PduInfoType PduInfoPtr;
    /* transmit confirmation */

        /* TxConfP is set */
        if(TRUE == TxBufferTableRuntimer[TxPduId].TxConfP)
        {
        do             
        {
            /* FIFO is empty only support CAN, FIFO = 0 */
            if((PDUR_CAN == PDUR_GWDESTTXPDU(TxPduId).BusType) 
                                && (TxBufferTableRuntimer[TxPduId].Count == 0u))
            {
                /* Clear TxConfP */
                TxBufferTableRuntimer[TxPduId].TxConfP = FALSE;
                result = E_OK;
            }
            /* FIFO contains only one entry support LIN, FIFO = 1 */
            else if((PDUR_LIN == PDUR_GWDESTTXPDU(TxPduId).BusType) 
                                    && (TxBufferTableRuntimer[TxPduId].Count  == 1u))
            {
                /* Clear TxConfP */
                TxBufferTableRuntimer[TxPduId].TxConfP = FALSE; 
                result = E_OK;
            }
            else
            {
                PduInfoPtr.SduLength = PDUR_GWDESTTXPDU(TxPduId).Length;
                PduInfoPtr.SduDataPtr = &PduRGWTxBuffer[TxBufferTableRuntimer[TxPduId].First];
               /* Call LoIf_Transmit API */
                result = PduRLoIf_Transmit[PDUR_GWDESTTXPDU(TxPduId).BusType](PDUR_GWDESTTXPDU(TxPduId).DestId, &PduInfoPtr);  
                PduR_DeQueueBuffer(TxPduId);
            }
    }while(E_OK != result);
    }

    return;    
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#endif /* endif #if(STD_ON == PDUR_CANIF_SUPPORT) */

#if(STD_ON == PDUR_LINIF_SUPPORT)
/******************************************************************************/
/*
 * Brief               Rx indicator for the LIN Interface
 *
 * ServiceId           0x0e
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      LinRxPduId:ID of LIN L-PDU that has been received.
 * 					   PduInfoPtr: Contains the lenght of the received I-PDU
 * 					   and a pointer to a buffer containing the I-PDU.
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(void, PDUR_CODE)
PduR_LinIfRxIndication(PduIdType LinRxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
    uint16 PduIndex = 0;

    #if(STD_ON == PDUR_DEV_ERROR_DETECT)
    boolean detNoErr = TRUE;
    /* @PDUR337 */
    if(PDUR_ONLINE != PduR_Status)
    {
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFRXINDICATION_ID, PDUR_E_INVALID_REQUEST);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && ((NULL_PTR == PduInfoPtr) || (NULL_PTR == PduInfoPtr->SduDataPtr)))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFRXINDICATION_ID, PDUR_E_DATA_PTR_INVALID);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && (LinRxPduId >= PDUR_MAX_IFSRCRXPDU_NUMBER))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFRXINDICATION_ID, PDUR_E_PDU_ID_INVALID);
    	detNoErr = FALSE;		
    }

    if(TRUE == detNoErr)
    #endif
    {
		for(PduIndex = PDUR_IFSRCRXPDU(LinRxPduId).StartId; PduIndex <= PDUR_IFSRCRXPDU(LinRxPduId).StopId; PduIndex++)
		{
			switch (PDUR_IFDESTRXPDU(PduIndex).UpType)
			{
				#if(STD_ON == PDUR_COM_SUPPORT)
				case PDUR_COM:
					Com_RxIndication(PDUR_IFDESTRXPDU(PduIndex).DestId, PduInfoPtr);
					break;
				#endif
				#if(STD_ON == PDUR_IPDUM_SUPPORT)
				case PDUR_IPDUMU:
					Ipdum_RxIndication(PDUR_IFDESTRXPDU(PduIndex).DestId, PduInfoPtr);
					break;
				#endif
				#if(STD_ON == PDUR_GATEWAY_OPERATION)
				case PDUR_GATEWAY:   
                    PduR_GWRxIndication(PDUR_IFDESTRXPDU(PduIndex).DestId, PduInfoPtr);
					break;
				#endif
				default:
					break;
			}

		}        
    }   

    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief               Tx Confirmation for the LIN Interface
 *
 * ServiceId           0x0f
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      LinTxPduId:ID of LIN L-PDU that has been transmitted.
 *					   PduInfoPtr:Contains a pointer to a buffer to where the
 *					   shall be copied to.
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              Std_ReturnType:
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(Std_ReturnType, PDUR_CODE)
PduR_LinIfTxConfirmation(PduIdType LinTxPduId)
{
    #if(STD_ON == PDUR_DEV_ERROR_DETECT)
    boolean detNoErr = TRUE;
    /* @PDUR337 */
    if(PDUR_ONLINE != PduR_Status)
    {
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFTXCONFIRMATION_ID, PDUR_E_INVALID_REQUEST);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && (LinTxPduId >= PDUR_MAX_IFCONFPDU_NUMBER))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFTXCONFIRMATION_ID, PDUR_E_PDU_ID_INVALID);
    	detNoErr = FALSE;		
    }
    if(TRUE == detNoErr)
    #endif
    {
        switch (PDUR_IFCONFPDU(LinTxPduId).UpType)
        {
            #if(STD_ON == PDUR_COM_SUPPORT)
             case PDUR_COM:
        	    Com_TxConfirmation(PDUR_IFCONFPDU(LinTxPduId).ConfId);
        	    break;
             #endif
            #if(STD_ON == PDUR_IPDUM_SUPPORT)
            case PDUR_IPDUMU:
        	    Ipdum_TxConfirmation(PDUR_IFCONFPDU(LinTxPduId).ConfId);
        	    break;
            #endif
            #if(STD_ON == PDUR_GATEWAY_OPERATION)
            case PDUR_GATEWAY:
                PduR_GWTxConfirmation(PDUR_IFCONFPDU(LinTxPduId).ConfId);
        	    break;
            #endif
            default:
        	    break;
        }           
        
    }
    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief               Triggers the transmission of a LIN frame
 *
 * ServiceId           0x10
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      LinTxPduId:ID of LIN L-PDU that has been transmitted.
 *
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              Std_ReturnType:E_OK,E_NOT_OK;
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(Std_ReturnType, PDUR_CODE)
PduR_LinIfTriggerTransmit(PduIdType LinTxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
    

    #if(STD_ON == PDUR_DEV_ERROR_DETECT)
    boolean detNoErr = TRUE;
    /* @PDUR337 */
    if(PDUR_ONLINE != PduR_Status)
    {
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFTRIGGERTRANSMIT_ID, PDUR_E_INVALID_REQUEST);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && ((NULL_PTR == PduInfoPtr) || (NULL_PTR == PduInfoPtr->SduDataPtr)))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFTRIGGERTRANSMIT_ID, PDUR_E_DATA_PTR_INVALID);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && (LinTxPduId >= PDUR_MAX_IFSRCRXPDU_NUMBER))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFTRIGGERTRANSMIT_ID, PDUR_E_PDU_ID_INVALID);
    	detNoErr = FALSE;		
    }

    if(TRUE == detNoErr)
    #endif
    {
        switch (PDUR_IFCONFPDU(LinTxPduId).UpType)
        {
            #if(STD_ON == PDUR_COM_SUPPORT)
             case PDUR_COM:
        	    Com_TriggerTransmit(PDUR_IFCONFPDU(LinTxPduId).ConfId);
        	    break;
             #endif
            #if(STD_ON == PDUR_IPDUM_SUPPORT)
            case PDUR_IPDUMU:
        	    Ipdum_TriggerTransmit(PDUR_IFCONFPDU(LinTxPduId).ConfId);
        	    break;
            #endif
            #if(STD_ON == PDUR_GATEWAY_OPERATION)
            case PDUR_GATEWAY:
                  PduInfoPtr->SduLength = PDUR_GWDESTTXPDU(LinTxPduId).Length;                        
                  PduR_Memcpy(PduInfoPtr->SduDataPtr, 
                                    &PduRGWTxBuffer[TxBufferTableRuntimer[LinTxPduId].First],
                                     PDUR_GWDESTTXPDU(LinTxPduId).Length);
                  PduR_DeQueueBuffer(LinTxPduId);
        	    break;
            #endif
            default:
        	    break;
        }           
    }  
    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

#endif /* #if(STD_ON == PDUR_LINIF_SUPPORT)  */

#if(STD_ON == PDUR_IPDUM_SUPPORT)
/******************************************************************************/
/*
 * Brief               Requests a tranmission for the IPDUM module
 *
 * ServiceId           0x19
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      IpdumTxPduId:ID of IPDUM I-PDU that has been transmitted.
 * 					   PduInfoPtr: Contains the lenght of the received I-PDU
 * 					   and a pointer to a buffer containing the I-SDU.
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              Std_ReturnType:E_OK,E_NOT_OK;
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(Std_ReturnType, PDUR_CODE)
PduR_IpdumTransmit(PduIdType IpdumTxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
    Std_ReturnType result = E_NOT_OK;

    #if(STD_ON == PDUR_DEV_ERROR_DETECT)
    boolean detNoErr = TRUE;
    /* @PDUR337 */
    if(PDUR_ONLINE != PduR_Status)
    {
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_IPDUMTRANSMIT_ID, PDUR_E_INVALID_REQUEST);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && ((NULL_PTR == PduInfoPtr) || (NULL_PTR == PduInfoPtr->SduDataPtr)))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_IPDUMTRANSMIT_ID, PDUR_E_DATA_PTR_INVALID);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && (IpdumTxPduId >= PDUR_MAX_COMDESTTXPDU_NUMBER))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_IPDUMTRANSMIT_ID, PDUR_E_PDU_ID_INVALID);
    	detNoErr = FALSE;
    }
    if(TRUE == detNoErr)
    #endif
    {
        /* IpduM call CanIf_Transmit or LinIf_Transmit */
    	result = PduRLoIf_Transmit[(PDUR_COMDESTTXPDU(IpdumTxPduId).BusType)](PDUR_COMDESTTXPDU(IpdumTxPduId).DestId, PduInfoPtr);
    }

    return result;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief               Tx confirmation for the IPDUM
 *
 * ServiceId           0x1a
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      IpdumLoTxPduId:ID of IPDUM L-PDU that has been Transmitted.
 *
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(void, PDUR_CODE)
PduR_IpdumTxConfirmation(PduIdType IpdumLoTxPduId)
{
   #if(STD_ON == PDUR_DEV_ERROR_DETECT)
    boolean detNoErr = TRUE;
    /* @PDUR337 */
    if(PDUR_ONLINE != PduR_Status)
    {
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_IPDUMTXCONFIRMATION_ID, PDUR_E_INVALID_REQUEST);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && (IpdumLoTxPduId >= PDUR_MAX_IFCONFPDU_NUMBER))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_IPDUMTXCONFIRMATION_ID, PDUR_E_PDU_ID_INVALID);
    	detNoErr = FALSE;		
    }
    if(TRUE == detNoErr)
    #endif
    {
        #if(STD_ON == PDUR_COM_SUPPORT)
        if(PDUR_COM == PDUR_IFCONFPDU(IpdumLoTxPduId).UpType)
        {
            Com_TxConfirmation(PDUR_IFCONFPDU(IpdumLoTxPduId).ConfId);
        }
        #endif
    }   
    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief               Rx indicator for the IPDUM
 *
 * ServiceId           0x1b
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      IpdumLoRxPduId:ID of CAN L-PDU that has been received.
 * 					   PduInfoPtr: Contains the lenght of the received I-PDU
 * 					   and a pointer to a buffer containing the I-PDU.
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(void, PDUR_CODE)
PduR_IpdumRxIndication(PduIdType IpdumLoRxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
    #if(STD_ON == PDUR_DEV_ERROR_DETECT)
	boolean detNoErr = TRUE;
	/* @PDUR337 */
	if(PDUR_ONLINE != PduR_Status)
	{
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_IPDUMRXINDICATION_ID, PDUR_E_INVALID_REQUEST);
		detNoErr = FALSE;
	}
	if ((TRUE == detNoErr) && ((NULL_PTR == PduInfoPtr) || (NULL_PTR == PduInfoPtr->SduDataPtr)))
	{
		/* @PDUR222 */
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_IPDUMRXINDICATION_ID, PDUR_E_DATA_PTR_INVALID);
		detNoErr = FALSE;
	}
	if ((TRUE == detNoErr) && (IpdumLoRxPduId >= PDUR_MAX_IPDUMRXPDU_NUMBER))
	{
		/* @PDUR222 */
		Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_IPDUMRXINDICATION_ID, PDUR_E_PDU_ID_INVALID);
		detNoErr = FALSE;		
	}

	if(TRUE == detNoErr)
	#endif
	{
           #if(STD_ON == PDUR_COM_SUPPORT)
           Com_RxIndication(PDUR_IPDUMRXPDU(IpdumLoRxPduId), PduInfoPtr);
           #endif		
	}
	return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/******************************************************************************/
/*
 * Brief               Triggers the transmission of a IpduM
 *
 * ServiceId           0x1c
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      IpdumTxPduId:ID of IPDUM L-PDU that has been transmitted.
 *
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              Std_ReturnType:E_OK,E_NOT_OK;
 * PreCondition        None
 * CallByAPI
 */
/******************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
FUNC(Std_ReturnType, PDUR_CODE)
PduR_IpdumTriggerTransmit(PduIdType IpdumTxPduId, P2CONST(PduInfoType, AUTOMATIC, PDUR_APPL_DATA) PduInfoPtr)
{
    

    #if(STD_ON == PDUR_DEV_ERROR_DETECT)
    boolean detNoErr = TRUE;
    /* @PDUR337 */
    if(PDUR_ONLINE != PduR_Status)
    {
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFTRIGGERTRANSMIT_ID, PDUR_E_INVALID_REQUEST);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && ((NULL_PTR == PduInfoPtr) || (NULL_PTR == PduInfoPtr->SduDataPtr)))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFTRIGGERTRANSMIT_ID, PDUR_E_DATA_PTR_INVALID);
    	detNoErr = FALSE;
    }
    if ((TRUE == detNoErr) && (IpdumTxPduId >= PDUR_MAX_IFCONFPDU_NUMBER))
    {
    	/* @PDUR222 */
    	Det_ReportError(PDUR_MODULE_ID, PDUR_INSTANCE_ID, PDUR_LINIFTRIGGERTRANSMIT_ID, PDUR_E_PDU_ID_INVALID);
    	detNoErr = FALSE;		
    }

    if(TRUE == detNoErr)
    #endif
    {
        #if(STD_ON == PDUR_COM_SUPPORT)
        if(PDUR_COM == PDUR_IFCONFPDU(IpdumTxPduId).UpType)
        {
            Com_TriggerTransmit(PDUR_IFCONFPDU(IpdumTxPduId).ConfId);
        }
        #endif	        
    }  
    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"


#endif /* #if(STD_ON == PDUR_IPDUM_SUPPORT) */

/*************************************************************************/
/*
 * Brief               MISRA C 2004 forbid to use memcpy() lib,only used  to 
 *                     copy data buffer of indirect address
 * ServiceId           None
 * Sync/Async          Synchronous
 * Reentrancy          Non Reentrant
 * Param-Name[in]      *source:pointer to the source 
 *                     length:copy how much length
 * Param-Name[out]     None
 * Param-Name[in/out]  *dest:pointer to the dest 
 * Return              void
 * PreCondition        None
 * CallByAPI           
 */
/*************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_Memcpy
(
    P2VAR(uint8, AUTOMATIC, AUTOMATIC) dest,
    P2CONST(uint8, AUTOMATIC, AUTOMATIC) source,
    uint16 length   
)
{
    while(length > 0u)
    {
		*dest = *source;
        dest++;
        source++;        
        length--;
    }
    
    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"

/*************************************************************************/
/*
 * Brief               MISRA C 2004 forbid to use memset() lib,only used  to  
 *                     set data buffer ofindirect address
 * ServiceId           None
 * Sync/Async          Synchronous
 * Reentrancy          Non Reentrant
 * Param-Name[in]      source:the source which want to be set 
 *                     length:copy how much length
 * Param-Name[out]     None
 * Param-Name[in/out]  *dest:pointer to the dest 
 * Return              void
 * PreCondition        None
 * CallByAPI           
 */
/*************************************************************************/
#define PDUR_START_SEC_CODE
#include "PduR_MemMap.h"
STATIC FUNC(void, PDUR_CODE)
PduR_Memset
(   P2VAR(uint8, AUTOMATIC, AUTOMATIC) dest,
    const uint8 source,
    uint16 length   
)
{
    while (length > 0u)
    {
		*dest = source;
		dest++;
		length--;
    }
    
    return;
}
#define PDUR_STOP_SEC_CODE
#include "PduR_MemMap.h"


#endif /* endif #if(STD_OFF == PDUR_ZERO_COST_OPERATION) */
/*=======[E N D   O F   F I L E]==============================================*/


